package com.zy.bean3;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

@Component
public class DBUtil {
    // SPEL表达式
    @Value("${db.driver}")
    private String driver;
    @Value("${db.url}")
    private String uri;
    @Value("${db.username}")
    private String username;
    @Value("${db.password}")
    private String password;

    public Connection getCon(){
        try {
            Class.forName(driver);
            return DriverManager.getConnection(uri, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
